package org.wolfengi.monitor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.wolfengi.monitor.common.ShipCN;
import org.wolfengi.monitor.entity.FShipFaultCount;
import org.wolfengi.monitor.mapper.FShipFaultCountMapper;
import org.wolfengi.monitor.service.FShipFaultCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wolfengi
 * @since 2020-05-20
 */
@Service
public class FShipFaultCountServiceImpl extends ServiceImpl<FShipFaultCountMapper, FShipFaultCount> implements FShipFaultCountService {

    @Autowired
    private FShipFaultCountMapper fShipFaultCountMapper;

    @Override
    public List<Map> selectShipFaultCount() {
        List<Map> maps = fShipFaultCountMapper.selectShipFaultCount();
        maps.forEach(l -> {
            String cn = ShipCN.getCNTrim(l.get("fault").toString().trim());
            if (null != cn) {
                l.put("cn", cn);
            } else {
                l.clear();
//                l.put("cn", l.get("fault").toString().trim());
            }
        });

        /**
         * 清楚不在ShipCN内的故障信息
         */
        Map<String, Object> map1 = new HashMap<>();
        List<Map<String, Object>> test1 = new ArrayList<>();
        test1.add(map1);
        maps.removeAll(test1);
        return maps;
    }
}
